﻿using Autofac;
using AutoMapper;
using Hrm.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hrm.Services
{
    public class ServiceModule
    {
        public static void Initialize()
        {
            Mapper.CreateMap<ResourceDto, Resource>();
            Mapper.CreateMap<Resource, ResourceDto>()
                .ForMember(p => p.ApplicationId, b => b.MapFrom(s => s.Application.Id))
                .ForMember(p => p.PermissionNames, b => b.MapFrom(s => s.ResourceAndPermissions.Select(x => x.Permission.Name)))
                .ForMember(p => p.ApplicationName, b => b.MapFrom(s => s.Application.Name));

            Mapper.CreateMap<UserDto, User>();
            Mapper.CreateMap<User, UserDto>()
                .ForMember(p => p.RoleName, b => b.MapFrom(s =>s.Roles.FirstOrDefault().Name))
                .ForMember(p => p.RoleNames, b => b.MapFrom(s => s.Roles.Select(x => x.Name)))
                .ForMember(p => p.Url, b => b.MapFrom(s => s.Roles.FirstOrDefault().Url));

            Mapper.CreateMap<ApplicationDto, Application>();
            Mapper.CreateMap<Application, ApplicationDto>();

            Mapper.CreateMap<ClassMate, ClassMateDto>()
                .ForMember(p => p.SchoolName, b => b.MapFrom(s => s.Schools.FirstOrDefault().Name));
            Mapper.CreateMap<ClassMateDto, ClassMate>();

            Mapper.CreateMap<Permission, PermissionDto>();
            Mapper.CreateMap<PermissionDto, Permission>();

            Mapper.CreateMap<Role, RoleDto>();
            Mapper.CreateMap<RoleDto, Role>();

            Mapper.CreateMap<PortfolioDto, Portfolio>();
            Mapper.CreateMap<Portfolio, PortfolioDto>();
                //.ForMember(p=>p.ImageUrl,b=>b.MapFrom(s=>s.Id));

            Mapper.CreateMap<Service, ServiceDto>();
            Mapper.CreateMap<ServiceDto, Service>();
        }
    }
}
